package com.xywl.escort.view.home

import android.os.Bundle
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.trello.rxlifecycle2.LifecycleTransformer
import com.xywl.escort.R
import com.xywl.escort.base.BaseActivity
import com.xywl.escort.bean.BaseResp
import com.xywl.escort.common.PreferenceKeys.TOKEN
import com.xywl.escort.utils.RxSPTool
import com.xywl.escort.utils.ToastUtil
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_new_welfare.*
import javax.inject.Inject

@Route(path = "/xy/new/welfare")
class NewWelfareActivity : BaseActivity(), NewWelfareContract.View {

    @Inject
    lateinit var mPresenter: NewWelfareContract.Presenter

    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_new_welfare)

        image_back.setOnClickListener {
            finish()
        }

        mPresenter.takeView(this)
        img_welfare_mid.setOnClickListener {
            val token = RxSPTool.getString(this, TOKEN)
            if (!TextUtils.isEmpty(token)) {
                mPresenter.processRedPacket(1)
            } else {
                ToastUtil.showTip(this, "用户未登录")
                ARouter.getInstance().build("/xy/login").navigation()
            }
        }
    }

    override fun isActive(): Boolean {
        return false
    }

    override fun processRedPacketSuccess(resp: BaseResp?) {
        ToastUtil.showTip(this, "领取成功")
    }

    override fun <T : Any?> bindToLife(): LifecycleTransformer<T> {
        return this.bindToLifecycle()
    }

    override fun processRedPacketFailure(msg: String?) {
        ToastUtil.showTip(this, msg)
    }

}
